<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016-06-30
 * Time: 11:23
 */



require_once('./Excel/PHPExcel.php');
$list = array(
    array('name'=>'1111111','mobile'=>'136789456','data'=>'2013/03/01'),
    array('name'=>'222222','mobile'=>'136789456','data'=>'2013/03/01'),
    array('name'=>'111333333','mobile'=>'136789456','data'=>'2013/03/01'),
    array('name'=>'5555555','mobile'=>'136789456','data'=>'2013/03/01'),

);
$objPHPExcel = new PHPExcel();
$objPHPExcel -> getProperties() -> setCreator("smeoa") -> setLastModifiedBy("smeoa") -> setTitle("Office 2007 XLSX Test Document") -> setSubject("Office 2007 XLSX Test Document") -> setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") -> setKeywords("office 2007 openxml php") -> setCategory("Test result file");
// Add some data
$i = 1;
$objPHPExcel -> setActiveSheetIndex(0)
             -> setCellValue("A$i", "姓名")
             -> setCellValue("B$i", "手机")
             -> setCellValue("C$i", "日期") ;
//dump($list);
foreach ($list as $val) {
    $i++;
    $objPHPExcel -> setActiveSheetIndex(0)
        -> setCellValue("A$i", $val["name"])
        -> setCellValue("B$i", $val["mobile"])
        -> setCellValue("C$i", $val["data"])
    ;
}
// Rename worksheet
$objPHPExcel -> getActiveSheet() -> setTitle('Contact');

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel -> setActiveSheetIndex(0);
$file_name = "contact.xlsx";
// Redirect output to a client��s web browser (Excel2007)
header("Content-Type: application/force-download");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition:attachment;filename =" . str_ireplace('+', '%20', URLEncode($file_name)));
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//readfile($filename);
$objWriter -> save('php://output');
exit ;